package com.org.khtn.gui;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Vector;

import com.org.khtn.command.Command;



class ProcessThread extends Thread {

    public ObjectOutputStream oos;
    public ObjectInputStream ois;
    public Socket ss;
    public Vector database;

    ProcessThread(Socket ss, Vector db) {

        super("ProcessThread");
        database = db;
        try {
            OutputStream os = ss.getOutputStream();
            oos = new ObjectOutputStream(os);

            InputStream is = ss.getInputStream();
            ois = new ObjectInputStream(is);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    public void run() {
    	boolean allow = true;
    	try {
    		oos.writeObject(database);
    	while(allow) {
    		
    		String strCommand = (String) ois.readObject();
    		if (strCommand.compareToIgnoreCase("!!!quit!!!")==0) {
    			allow = false;
    			oos.close();
    			ois.close();
    		} else {
    			String dbName = (String) ois.readObject();
    			Command command = new Command(strCommand, dbName);
    			Vector result = new Vector();
    			result = command.execute();
    			oos.writeObject(result);
    		}
    	}
    	} catch (Exception ex) {
  
        }
    	
    }
}
